package com.hardson.toolkit.swing;

import java.awt.Component;
import java.awt.Dimension;

public class SizeUtil {

	public static Dimension changedHeight(final Dimension dim, final int newHeight) {
		return new Dimension(dim.width, newHeight);
	}

	public static Dimension changedWidth(final Dimension dim, final int newWidth) {
		return new Dimension(newWidth, dim.height);
	}

	public static Dimension changePreferredWidth(final Component comp, final int newWidth) {
		Dimension d = comp.getPreferredSize();
		d.width = newWidth;
		comp.setPreferredSize(d);
		return new Dimension(d.width, d.height);
	}

	public static Dimension changePreferredHeight(final Component comp, final int newHeight) {
		Dimension d = comp.getPreferredSize();
		d.height = newHeight;
		comp.setPreferredSize(d);
		return new Dimension(d.width, d.height);
	}

	public static Dimension changeWidth(final Component comp, final int newWidth) {
		Dimension d = comp.getSize();
		d.width = newWidth;
		comp.setSize(d);
		return new Dimension(d.width, d.height);
	}

	public static Dimension changeHeight(final Component comp, final int newHeight) {
		Dimension d = comp.getSize();
		d.height = newHeight;
		comp.setSize(d);
		return new Dimension(d.width, d.height);
	}

	public static Dimension changeMaximumWidth(final Component comp, final int newWidth) {
		Dimension d = comp.getMaximumSize();
		d.width = newWidth;
		comp.setMaximumSize(d);
		return new Dimension(d.width, d.height);
	}

	public static Dimension changeMaximumHeight(final Component comp, final int newHeight) {
		Dimension d = comp.getMaximumSize();
		d.height = newHeight;
		comp.setMaximumSize(d);
		return new Dimension(d.width, d.height);
	}

	public static Dimension changeMinimumWidth(final Component comp, final int newWidth) {
		Dimension d = comp.getMinimumSize();
		d.width = newWidth;
		comp.setMinimumSize(d);
		return new Dimension(d.width, d.height);
	}

	public static Dimension changeMinimumHeight(final Component comp, final int newHeight) {
		Dimension d = comp.getMinimumSize();
		d.height = newHeight;
		comp.setMinimumSize(d);
		return new Dimension(d.width, d.height);
	}

	public static void fixSize(final Component comp, final int width, final int height) {
		comp.setMaximumSize(new Dimension(width, height));
		comp.setPreferredSize(new Dimension(width, height));
	}

	public static void fixSize(final Component comp, final Dimension dim) {
		comp.setMaximumSize(new Dimension(dim.width, dim.height));
		comp.setPreferredSize(dim);
	}
}
